package com.CMS.server.domain;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name = EntityTokens.ROL_TABLE)
public class Rol extends BaseEntity{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 3090092459882332852L;
	
	//ESTO LO QUE HACE ES ARMAR LA RELACION NN ENTRE ROL Y PRIVILEGE
	@ManyToMany(fetch = FetchType.EAGER, cascade ={CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH})
	@JoinTable(name= EntityTokens.ROL_PRIVILEGE_JOINNED, 
			joinColumns = {@JoinColumn(name = EntityTokens.ROL_ID_JOINNED, referencedColumnName = EntityTokens.BASEENTITY_ID_COLUMN)},
			inverseJoinColumns = {@JoinColumn(name = EntityTokens.PRIVILEGE_ID_JOINNED, referencedColumnName= EntityTokens.BASEENTITY_ID_COLUMN)})
	protected List<Privilege> privilegios;
	
	public Rol(){
		super();
		privilegios = new ArrayList<Privilege>();
	}
	
	public void addPrivilege(Privilege p){
		privilegios.add(p);
	}
	
	public List<Privilege> getPrivileges(){
		return privilegios;
	}
	
	public void setPrivileges(List<Privilege> lista){
		privilegios = lista;
	}
}
